package cn.tukk.sparkproject.test.testOrder;

import cn.tukk.sparkproject.spark.session.MyCategorySortKey;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

/*
 */
public class Myorder {
    public static void main(String[] args) {

        MyCategorySortKey my1=new MyCategorySortKey(12,15,20);
        MyCategorySortKey my2=new MyCategorySortKey(15,15,20);
        MyCategorySortKey my3=new MyCategorySortKey(12,15,16);
        MyCategorySortKey my4=new MyCategorySortKey(12,17,16);
        List<MyCategorySortKey> list=new ArrayList<MyCategorySortKey>();
        list.add(my1);
        list.add(my2);
        list.add(my3);
        list.add(my4);

        // 按点击数倒序
        Collections.sort(list, new Comparator<MyCategorySortKey>() {
            public int compare(MyCategorySortKey arg0, MyCategorySortKey arg1) {
                if(arg0.getClickCount()-arg1.getClickCount()!=0){
                    if(arg0.getClickCount()-arg1.getClickCount()>0){//倒序
                        return  -1;
                    }if(arg0.getClickCount()-arg1.getClickCount()<0){
                        return 1;
                    }else {
                        return 0;
                    }

                }else if(arg0.getOrderCount()-arg1.getOrderCount()!=0){
                    return (int) (arg0.getOrderCount()-arg1.getOrderCount());
                }else if(arg0.getPayCount()-arg1.getPayCount()!=0){
                    return (int) (arg0.getPayCount()-arg1.getPayCount());
                }
               return 0;
            }
        });

        for (MyCategorySortKey my:list
             ) {
            System.out.println(my);
        }
    }

}
